//
//  QRCreatFinishedViewController.m
//  EducationOID
//
//  Created by slz on 2017/6/7.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "QRCreatFinishedViewController.h"
#import <ZXingWrapper.h>
#import <LBXScanView.h>
#import "NSString+OIDAnalysis.h"
#import "QRCodeGenerator.h"

@interface QRCreatFinishedViewController ()
@property (nonatomic,strong) UIImageView *codeImageView;
@property (nonatomic,strong) CALayer *lineLayer;
@property (nonatomic,strong) UILabel *souceStringLabel;
@end

@implementation QRCreatFinishedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.showNavigationBar = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    UIBarButtonItem * item = [UIBarButtonItem itemWithImage:@"top_back_1" selectImage:nil addTarget:self andAction:@selector(backAction)];
    self.navigationItem.leftBarButtonItem = item;
    [self setControllerTitle:@"生成码"];
    
    _codeImageView = [UIImageView new];
    _lineLayer = [CALayer new];
    _lineLayer.size = CGSizeMake(kScreenWidth - 20, 5);
    _lineLayer.backgroundColor = kLineColor_Gray_Default.CGColor;
    
    _souceStringLabel = [UILabel new];
    _souceStringLabel.textColor = kDark_TextColor_Default;
    _souceStringLabel.fontSize = 14;
    _souceStringLabel.text = _sourceString;
    [self.view addSubview:_souceStringLabel];
    
    UIImage * showImage = nil;
    if (_isQrCode){
        showImage = [QRCodeGenerator qrImageForString:_sourceString imageWidth:kScreenWidth - 20 logo:nil];
        _codeImageView.frame = CGRectMake(10, 20, kScreenWidth - 20, kScreenWidth - 20);
    }else{
        showImage = [ZXingWrapper createCodeWithString:_sourceString size:_codeImageView.bounds.size CodeFomart:kBarcodeFormatCode128];
        _codeImageView.frame = CGRectMake(10, 20, kScreenWidth - 20, 100);
    }
    _lineLayer.top = _codeImageView.bottom + 20;
    _lineLayer.left = 10;
    [self.view.layer addSublayer:_lineLayer];

    _codeImageView.image = showImage;
    [self.view addSubview:_codeImageView];

    [_souceStringLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).offset(11);
        make.top.mas_equalTo(_codeImageView.mas_bottom).offset(40);
    }];
    
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
